﻿using System;
using UnityEngine;

namespace ProjectDanmaku.Audio
{
    [RequireComponent(typeof(AudioSource))]
    public class LoopMusic : MonoBehaviour
    {
        private AudioSource _audio;

        [SerializeField] private float startTime;
        [SerializeField] private float clipBeginTime;
        [SerializeField] private float clipJumpBackTime;

        private void Awake()
        {
            _audio = GetComponent<AudioSource>();
        }

        private void Start()
        {
            _audio.time = startTime;
        }

        private void Update()
        {
            if (_audio.time >= clipJumpBackTime)
            {
                _audio.time = clipBeginTime;
            }
        }
    }
}